package com.redis1.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.scheduling.annotation.Async;

/**
 * @author: LI-CI-GAO
 * 作者: licigao
 * 日期: 2021/8/25  15:35
 * 描述:
 */

@Configuration
public class TestRedisConfig {

    @Autowired
   private RedisConnectionFactory redisConnectionFactory;

    /**
     * 作者: LI-CI-GAO
     * 日期: 2021/8/25  15:38
     * 描述: redis  JDK 序列化
     * @Param []
     * @Return org.springframework.data.redis.core.RedisTemplate
     */
 /*  @Bean("redisTemplateJdk")
   public RedisTemplate test01(){

       RedisTemplate redisTemplate=new RedisTemplate();

       redisTemplate.setConnectionFactory(redisConnectionFactory);
       redisTemplate.setKeySerializer(new StringRedisSerializer());
       redisTemplate.setValueSerializer(new JdkSerializationRedisSerializer());


       return redisTemplate;
   }*/


   /*@Bean("redisTemplateJkson")
   public RedisTemplate<String,Object> test02(){
       RedisTemplate<String,Object> redisTemplate=new RedisTemplate();

       redisTemplate.setConnectionFactory(redisConnectionFactory);
       redisTemplate.setKeySerializer(new StringRedisSerializer());
       redisTemplate.setValueSerializer(new Jackson2JsonRedisSerializer<Object>(Object.class));

       redisTemplate.setHashKeySerializer(new StringRedisSerializer());
       redisTemplate.setHashValueSerializer(new Jackson2JsonRedisSerializer<Object>(Object.class));

       return redisTemplate;
   }*/


    @Bean
    public RedisTemplate<String,Object> test04(RedisConnectionFactory redisConnectionFactory){
        RedisTemplate<String,Object> redisTemplate=new RedisTemplate();
        redisTemplate.setConnectionFactory(redisConnectionFactory);
        return redisTemplate;
    }

   /* @Bean("redisTemplateGeneric")
    public RedisTemplate<String,Object> test03(){
        RedisTemplate<String,Object> redisTemplate=new RedisTemplate();

        redisTemplate.setConnectionFactory(redisConnectionFactory);
        redisTemplate.setKeySerializer(new StringRedisSerializer());
        redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer());

        return redisTemplate;
    }*/


}
